<template>
	<view class="container">
		<u-navbar :title-bold='true' :border-bottom='false'>
			<view class="bar">
				生活所系，信任相托
			</view>
		</u-navbar>
		<u-search bg-color='#FFF' @change="search" margin="0" class="search" placeholder="搜索姓名" :show-action="false"
			v-model="keyword"></u-search>
		<view class="topic">
			<view @click="select(index)" :class="index==t_index?'select':''" class="t-item"
				v-for="(item,index) in topic" :key="index">
				<span>{{item}}</span>
			</view>
		</view>

		<view v-if="list.length<1" class="noData">
			暂无数据
		</view>

		<view class="content" v-for="(item,idx) in list" :key="idx">
			<view class="card">
				<view class="top">
					<view class="c-t">
						<image src="@/static/img/review/icon.png" mode="widthFix"></image>
						<span>{{item.order_sn||''}}</span>
					</view>
					<span class="statu">{{item.status_text||''}}</span>
				</view>
				<u-line></u-line>
				<view class="center">
					<view class="userInfo" @click="goTo('/sub/center/mine/umbrellaDetail?id='+item.id)">
						<u-avatar size='large' mode="square" :src="item.user_info.avatar"></u-avatar>

						<view class="dsc">
							<view class="d1">
								<!-- 医师 -->
								<span class="s1">{{item.user_info.username}}</span>
								<span>{{item.user_info.speciality||''}}</span>
							</view>
							<view class="d2">
								<span class="s1"></span>
								<!-- 感谢 -->
								<span>{{item.goods_name}}</span>
								<span style="margin-left: 10rpx;">x{{item.num||0}}</span>
							</view>
							<view class="d2">
								<span class="s1"></span>
								<span>{{item.msg||''}}</span>
							</view>
							<view class="d2">
								<span class="s1"></span>
								<span>{{item.member_info||'未添加成员'}}</span>
							</view>
						</view>
					</view>
					<view class="button">
						<!-- 护航员端 -->
						<span v-if="user.job==2" @click.stop="tochat(item.user_id)">联系用户</span>
						<span v-if="item.bind_status==1 && user.job!=2"
							@click.stop="goTo('/sub/center/mine/binding_member?id='+item.id)">绑定成员</span>
						<!-- <span>查看详情</span> -->
					</view>
				</view>

			</view>
			<view class="bto">
				<span>有效期</span>{{item.start_time+'~'+item.end_time}}
			</view>
		</view>
		<!-- 提示 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		myProtect,
		memberList,
		myThank,
		chat
	} from '@/api/index.js'
	export default {
		data() {
			return {
				list: [],
				topic: ['全部', '生效中', '已过期'],
				t_index: 0,
				keyword: '',
				page: 1,
				user: {},
				status: ''
			}
		},

		onShow() {
			this.page = 1
			this.list = []
			this.init()
		},
		onReachBottom() { //监听页面触底函数
			this.init()
		},
		methods: {
			init() {
				let that = this;
				that.user = that.ws.getUserInfo()
				let obj = {
					'page': that.page,
					'per_page': 10,
					'status': that.status,
					'keyword': that.keyword
				}
				if (that.user.job == 2) {
					myThank(obj).then(res => {
						if (res.code == 1) {
							that.list = [...that.list, ...res.data.list.data]
							that.page++

						} else {
							that.$refs.uToast.show({
								title: res.msg
							})
						}

					})
				} else {
					myProtect(obj).then(res => {
						if (res.code == 1) {
							that.list = [...that.list, ...res.data.list.data]
							that.page++

						} else {
							that.$refs.uToast.show({
								title: res.msg
							})
						}

					})
				}

			},
			select(idx) {
				this.t_index = idx
				if (idx == 1) {
					this.status = idx
				}
				if (idx == 2) {
					this.status = 3
				}
				if (idx == 0) {
					this.status = ''
				}
				this.page = 1
				this.list = []
				this.init()
			},
			search() {
				this.list = []
				this.page = 1
				this.init()
			},

			goTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			tochat(id) {
				let that = this
				chat({
					'user_id': id
				}).then(res => {
					if (res.code == 1) {
						that.ws.tochat(res.data.session_id)
					}
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.container {
		height: 100vh;
		background-color: #EEE;
		padding: 15px;

		.u-nav-slot {
			display: flex;
		}

		.bar {
			width: 100%;
			font-weight: bold;
			text-align: center;
			font-size: 16px;
		}

		.noData {
			width: 100%;
			margin-top: 30%;
			text-align: center;
		}

		.topic {
			display: flex;
			justify-content: space-between;
			margin: 20rpx 0;
			color: #3D3D3D;
			font-size: 15px;

			.t-item {
				text-align: center;
				padding: 16rpx 20rpx;
			}

			.select {
				border-bottom: 2px solid #6EC9E1;
				color: #6EC9E1;
				font-weight: bold;
			}
		}

		.content {
			margin-top: 20rpx;

			.card {
				padding: 20rpx;
				background-color: #FFF;
				border-radius: 20rpx;

				.top {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 20rpx;
					font-size: 14px;

					.c-t {
						image {
							height: 12px;
							width: 12px;
							margin-right: 10rpx;
						}

						.statu {
							font-size: 18px;
						}
					}
				}

				.center {
					font-size: 14px;
					padding-bottom: 40rpx;

					.button {
						display: flex;
						justify-content: flex-end;

						span {
							border-radius: 30rpx;
							border: 1rpx solid #D8D8D8;
							padding: 0 20rpx;
							margin-left: 20rpx;
							height: 30px;
							line-height: 30px;
						}
					}

					.userInfo {
						margin: 30rpx 0;
						display: flex;

						.dsc {
							margin-left: 16rpx;

							span {
								opacity: 0.5;
							}

							.d1 {
								.s1 {
									margin-right: 10rpx;
									font-size: 18px;
									font-weight: bold;
									opacity: 1;
								}
							}

							.d2 {
								display: flex;
								align-items: center;
								margin: 10rpx 0;

								.s1 {
									margin-right: 10rpx;
									display: block;
									background-color: #151515;
									border-radius: 50%;
									height: 10rpx;
									width: 10rpx;
								}
							}

						}
					}
				}
			}
		}

		.bto {
			position: relative;
			top: -20rpx;
			display: inline-flex;
			align-items: center;
			width: 100%;
			background-color: #F5FDFF;
			color: #6EC9E1;
			padding: 20rpx;
			font-size: 15px;

			span {
				padding: 4rpx 10rpx;
				background-color: #6EC9E1;
				color: #EEE;
				border-radius: 30rpx;
				font-size: 13px;
				margin-right: 10rpx;
			}
		}
	}
</style>